(read_key_sequence): Read the first char specially
authorRichard M. Stallman <rms@gnu.org>
Sun, 30 May 1993 04:49:24 +0000 (04:49 +0000)
committerRichard M. Stallman <rms@gnu.org>
Sun, 30 May 1993 04:49:24 +0000 (04:49 +0000)
before the main loop.

src/keyboard.c

index fdfe3b5dfece76206087c0e218bcb2b6d68e1e30..8dba1d098e9d925956872a857573a690de5d6cc1 100644 (file)
@@ -3597,19 +3597,25 @@ read_key_sequence (keybuf, bufsize, prompt)
      recognized a function key, to avoid searching for the function
      key's again in Vfunction_key_map.  */
   int fkey_start = 0, fkey_end = 0;
-  Lisp_Object fkey_map = Vfunction_key_map;
+  Lisp_Object fkey_map;
 
   /* If we receive a ``switch-frame'' event in the middle of a key sequence,
      we put it off for later.  While we're reading, we keep the event here.  */
-  Lisp_Object delayed_switch_frame = Qnil;
+  Lisp_Object delayed_switch_frame;
 
+  Lisp_Object first_event;
+
+  int junk;
+
+  last_nonmenu_event = Qnil;
+
+  delayed_switch_frame = Qnil;
+  fkey_map = Vfunction_key_map;
 
   /* If there is no function key map, turn off function key scanning.  */
   if (NILP (Fkeymapp (Vfunction_key_map)))
     fkey_start = fkey_end = bufsize + 1;
 
-  last_nonmenu_event = Qnil;
-
   if (INTERACTIVE)
     {
       if (prompt)
@@ -3626,6 +3632,11 @@ read_key_sequence (keybuf, bufsize, prompt)
     echo_start = echo_length ();
   keys_start = this_command_key_count;
 
+  /* Read the first char of the sequence specially, before setting
+     up any keymaps, in case a filter runs and switches buffers on us.  */
+  first_event = read_char (!prompt, 0, submaps, last_nonmenu_event,
+                          &junk);
+
   /* We jump here when the key sequence has been thoroughly changed, and
      we need to rescan it starting from the beginning.  When we jump here,
      keybuf[0..mock_input] holds the sequence we should reread.  */
@@ -3724,8 +3735,14 @@ read_key_sequence (keybuf, bufsize, prompt)
        {
          last_real_key_start = t;
 
-         key = read_char (!prompt, nmaps, submaps, last_nonmenu_event,
-                          &used_mouse_menu);
+         if (! NILP (first_event))
+           {
+             key = first_event;
+             first_event = Qnil;
+           }
+         else
+           key = read_char (!prompt, nmaps, submaps, last_nonmenu_event,
+                            &used_mouse_menu);
 
          /* read_char returns -1 at the end of a macro.
             Emacs 18 handles this by returning immediately with a